package nju.mscs.gui;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;

import nju.mscs.businesslogic.*;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class CopyOflogin4_m extends javax.swing.JFrame {
	private JLabel jLabel1;
	private JLabel jLabel2;
	private JButton jButton1;
	private JLabel jLabel3;
	private JTextField jTextField1;

	private LogIn log;
	private JButton jButton2;
	private JPasswordField jPasswordField1;
	private  static String key = "1"; 
	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				CopyOflogin4_m inst = new CopyOflogin4_m();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
				
			}
		});
	}
	
	public CopyOflogin4_m() {
		super();
		initGUI();
		System.out.println("!@#!$!$!%");
	}
	public static void setKey(String a){
		key = a;
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			this.setUndecorated(true);
			{
				jLabel1 = new JLabel();
				getContentPane().add(jLabel1);
				jLabel1.setText("\u7cfb\u7edf\u7ba1\u7406\u5458\u8bf7\u767b\u5f55");
				jLabel1.setBounds(393, 24, 690, 131);
				jLabel1.setFont(new java.awt.Font("微软雅黑",0,72));
			}
			{
				jLabel2 = new JLabel();
				getContentPane().add(jLabel2);
				jLabel2.setText("\u7528\u6237\u540d\uff1a");
				jLabel2.setBounds(381, 228, 221, 88);
				jLabel2.setFont(new java.awt.Font("微软雅黑",0,48));
			}
			{
				jTextField1 = new JTextField();
				getContentPane().add(jTextField1);
				jTextField1.setBounds(654, 228, 325, 86);
				jTextField1.setFont(new java.awt.Font("微软雅黑",0,36));
			}
			{
				jLabel3 = new JLabel();
				getContentPane().add(jLabel3);
				jLabel3.setText("\u5bc6\u7801\uff1a");
				jLabel3.setBounds(381, 374, 183, 91);
				jLabel3.setFont(new java.awt.Font("微软雅黑",0,48));
			}
			{
				jButton1 = new JButton();
				getContentPane().add(jButton1);
				jButton1.setText("\u767b\u5f55");
				jButton1.setBounds(286, 554, 226, 116);
				jButton1.setFont(new java.awt.Font("微软雅黑",0,48));
				jButton1.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						jButton1ActionPerformed(evt);
					}
				});
			}
			{
				jPasswordField1 = new JPasswordField();
				getContentPane().add(jPasswordField1);
				jPasswordField1.setBounds(654, 377, 325, 84);
				jPasswordField1.setFont(new java.awt.Font("微软雅黑",0,36));
				jPasswordField1.addKeyListener(new KeyAdapter() {
					public void keyPressed(KeyEvent evt) {
						jPasswordField1KeyPressed(evt);
					}
				});
			}
			{
				jButton2 = new JButton();
				getContentPane().add(jButton2);
				jButton2.setText("\u8fd4\u56de");
				jButton2.setBounds(824, 554, 221, 116);
				jButton2.setFont(new java.awt.Font("微软雅黑",0,48));
				jButton2.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						jButton2ActionPerformed(evt);
					}
				});
			}
			pack();
			this.setSize(1237, 730);
			getGraphicsConfiguration().getDevice().setFullScreenWindow(this);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}
	
	private void jButton1ActionPerformed(ActionEvent evt) {
		//System.out.println("jButton1.actionPerformed, event="+evt);
		String username = jTextField1.getText();
		String password = jPasswordField1.getText();
		if (username.equals("")){
			JOptionPane.showMessageDialog(this,"用户名不允许为空！");
			return;}
		if (password.equals("")){
			JOptionPane.showMessageDialog(this,"密码不允许为空！");
			return;}
		log = new LogIn();
	   int b = log.matching(username,password,3);
		if(b==1)
		{
		CopyOfUser.main(null);
		this.dispose();
		}
		else{
			JOptionPane.showMessageDialog(this,"用户名或密码不正确！");
			return;}
	}//登录按钮事件响应
	
	
	private void jPasswordField1KeyPressed(KeyEvent evt) {
		//System.out.println("jPasswordField1.keyPressed, event="+evt);
		if(evt.getKeyCode()==KeyEvent.VK_ENTER){
			String username = jTextField1.getText();
			String password = jPasswordField1.getText();
			if (username.equals("")){
				JOptionPane.showMessageDialog(this,"用户名不允许为空！");
				return;}
			if (password.equals("")){
				JOptionPane.showMessageDialog(this,"密码不允许为空！");
				return;}
			log = new LogIn();
		   int b = log.matching(username,password,3);
			if(1==b)
			{
			CopyOfUser.main(null);
			this.dispose();
			}
			else{
				JOptionPane.showMessageDialog(this,"用户名或密码不正确！");
				return;}
			}
	}
	
	private void jButton2ActionPerformed(ActionEvent evt) {
		//System.out.println("jButton2.actionPerformed, event="+evt);
		if(key.equals("1")){
		Entrance_m.main(null);}
		else
			Entrance_s.main(null);
		this.dispose();
	}//返回按钮

}
